﻿
//
$(document).ready(function () {
    //登录
    $("#login").on("click", function () {
        if ("" == $("#userName").val()) {
            dialog({
                quickClose: true,
                content: "请输入用户名",
                height: "1em",
                onclose: function () { $("#userName").focus(); },
                follow: $("#userName")[0]
            }).show();
            return false;
        }

        if ("" == $("#passWord").val()) {
            dialog({
                quickClose: true,
                content: "请输入用密码",
                height: "1em",
                onclose: function () { $("#passWord").focus(); },
                follow: $("#passWord")[0]
            }).show();
            return false;
        }
        var jsonObject = { "userName": $("#userName").val(), "passWord": $("#passWord").val() };
        $.ajax({
            type: "POST",
            url: "/Account/AuthUser",
            contentType: "application/json",
            data: JSON.stringify(jsonObject),
            dataType: "json",
            success: function (data) {
                if (data.RetCode > 0) {
                    self.location.href = "/Setting/ActionManager/";
                }
                else {
                    dialog({
                        title: "提示",
                        width: "10em",
                        height: "1em",
                        content: "用户名或密码错误！",
                    }).width(220).show();

                }
            }
        })


    });

    //退出登录
    $("#logout").on("click", function () {
        $.ajax({
            type: "POST",
            url: "/Account/Logout",
            dataType: "json",
            success: function (data) {
                self.location.href = "/Setting/ActionManager";
            }
        })
    });

    $("#updateAdmin").on("click", function () {
        if ("" == $("#userName").val()) {
            dialog({
                quickClose: true,
                content: "请输入用户名",
                height: "1em",
                onclose: function () { $("#userName").focus(); },
                follow: $("#userName")[0]
            }).show();
            return false;
        }

        if ("" == $("#passWord").val()) {
            dialog({
                quickClose: true,
                content: "请输入用密码",
                height: "1em",
                onclose: function () { $("#passWord").focus(); },
                follow: $("#passWord")[0]
            }).show();
            return false;
        }

        var jsonObject = { "Username": $("#userName").val(), "Password": $("#passWord").val(), "Id": $("#userId").val() };
        $.ajax({
            type: "POST",
            url: "/Account/Editadminuser",
            contentType: "application/json",
            data: JSON.stringify(jsonObject),
            dataType: "json",
            success: function (data) {
                if (data.RetCode > 0) {
                    dialog({
                        title: "提示",
                        width: "10em",
                        height: "1em",
                        content: "更新成功",
                        onclose: function () { self.location.href = "/Setting/ActionManager"; },
                    }).width(220).show();
                }
                else {
                    dialog({
                        title: "提示",
                        width: "10em",
                        height: "1em",
                        content: "更新失败！",
                    }).width(220).show();

                }
            }
        });



    });


});